# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=dateutil
_pyname=python-dateutil
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-$_realname" "${MINGW_PACKAGE_PREFIX}-python3-$_realname")
pkgver=2.6.0
pkgrel=3
pkgdesc="Provides powerful extensions to the standard datetime module (mingw-w64)"
arch=('any')
license=('custom:PYTHON')
url="https://labix.org/python-dateutil"
makedepends=(
            "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
            "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
            "${MINGW_PACKAGE_PREFIX}-python2-six"
            "${MINGW_PACKAGE_PREFIX}-python3-six"
)
source=(https://github.com/dateutil/dateutil/releases/download/$pkgver/${_pyname}-$pkgver.tar.gz{,.asc})
validpgpkeys=("6B49ACBADCF6BD1CA20667ABCD54FCE3D964BEFB")
sha256sums=('62a2f8df3d66f878373fd0072eacf4ee52194ba302e00082828e0d263b0418d2'
            'SKIP')

prepare() {
  cd "${srcdir}"
 for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_pyname}-${pkgver}" "python${pver}-build-${CARCH}"
  done
}

build() {  
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check() {  
  for pver in {2,3}; do  
    msg "Python ${pver} test for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py test
  done  
}

package_python3-dateutil() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-six")

  cd "${srcdir}/python3-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root=${pkgdir} --optimize=1 --skip-build

  local _py3basever=$(${MINGW_PREFIX}/bin/python3 -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")

  install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE
  chmod -R a+r $pkgdir/${MINGW_PREFIX}/lib/python${_py3basever}/

  # Remove data files
  #rm ${pkgdir}${MINGW_PREFIX}/lib/python${_py3basever}/site-packages/dateutil/zoneinfo/dateutil-zoneinfo.tar.gz
}

package_python2-dateutil() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-six")

  cd "${srcdir}/python2-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root=${pkgdir} --optimize=1 --skip-build

  local _py2basever=$(${MINGW_PREFIX}/bin/python2 -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")

  install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE
  chmod -R a+r ${pkgdir}/${MINGW_PREFIX}/lib/python${_py2basever}/

  # Remove data files
  #rm ${pkgdir}${MINGW_PREFIX}/lib/python${_py2basever}/site-packages/dateutil/zoneinfo/dateutil-zoneinfo.tar.gz
}

package_mingw-w64-i686-python2-dateutil() {
  package_python2-dateutil
}

package_mingw-w64-i686-python3-dateutil() {
  package_python3-dateutil
}

package_mingw-w64-x86_64-python2-dateutil() {
  package_python2-dateutil
}

package_mingw-w64-x86_64-python3-dateutil() {
  package_python3-dateutil
}
